package com.xxxx.manager.controller;

import com.xxxx.manager.service.UploadService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

@Controller
public class UploadController {

    @Resource
    private UploadService uploadService;

    @RequestMapping("fileUpload/save")
    @ResponseBody
    public Map<String,Object> upload(MultipartFile file) throws Exception{

        Map<String, Object> map = new HashMap<>();

        InputStream inputStream = file.getInputStream();
        String fileName = file.getOriginalFilename();

        String fileUrl = uploadService.upload(inputStream, fileName);
        map.put("fileUrl",fileUrl);
        return map;
    }
}
